//
//  ViewController.m
//  垃圾管理者
//
//  Created by Steven on 2019/7/24.
//  Copyright © 2019 Steven. All rights reserved.
//

#import "ViewController.h"
#import "ListVC.h"
#import "AppCenter.h"
#import "NSArray+Util.h"


@interface ViewController ()
@property(nonatomic, strong)NSDictionary *allData;
@end

@implementation ViewController

- (NSDictionary *)allData{
    if (_allData == nil) {
        _allData = [NSDictionary dictionary];
    }
    return _allData;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.allData = [self readLocalFile];
    
    [self getAllDatas:@"1"];
    [self getAllDatas:@"2"];
    [self getAllDatas:@"3"];
    [self getAllDatas:@"4"];

}

- (void)getAllDatas:(NSString *)key{
    for (NSDictionary *dic in self.allData[key]) {
        [appData.homeDatas addObject:dic];
    }
}

- (NSDictionary *)readLocalFile{
    // 获取文件路径
    NSString *path = [[NSBundle mainBundle] pathForResource:@"refuseClassifyDic" ofType:@"json"];
    // 将文件数据化
    NSData *data = [[NSData alloc] initWithContentsOfFile:path];
    // 对数据进行JSON格式化并返回字典形式
    return [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
}


- (IBAction)toListAction:(UIButton *)sender {
    
    NSArray *titleArray = @[@"湿垃圾", @"干垃圾", @"可回收物", @"有害垃圾"];
    ListVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ListVC"];
    
    vc.dataArray = self.allData[[NSString stringWithFormat:@"%ld", sender.tag + 1]];
    
    vc.title = titleArray[sender.tag];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
